package com.hulk.dryad.common.constant.enums;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.EnumSet;

/**
 * @author hulk
 * @E-mail: 29572320@qq.com
 */
public enum UseFlag {

	YES("Y","UseFlag_Y"),
	NO("N","UseFlag_N");

	@Getter
	private String value;
	private String desc;

	UseFlag(String value, String desc) {
		this.value = value;
		this.desc = desc;
	}

	public String getDesc() {
		return messageSource.getMessage(desc, null, desc, LocaleContextHolder.getLocale());
	}


	private MessageSource messageSource;

	public UseFlag setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
		return this;
	}

	@Component
	public static class ReportTypeServiceInjector {

		@Autowired
		private MessageSource messageSource;

		@PostConstruct
		public void postConstruct() {
			for (UseFlag ec : EnumSet.allOf(UseFlag.class)) {
				ec.setMessageSource(messageSource);
			}
		}
	}
}
